package controllers

import (
	"os/exec"
	"gosync/utils"
	"gosync/models"
	"github.com/astaxie/beego"
)

type PublishController struct {
	BaseController
}


/*
项目管理
 */
func (this *PublishController) List(){


	this.setTpl("publish_list.html")
}

/*
发布申请
 */
func (this *PublishController) NewPub(){
	id, _ := this.GetInt("id")
	if id==0{
		this.ajaxReturn("", "项目ID丢失", 400)
	}
	//model_project := models.Project{}
	//project_info,_ := model_project.GetOne(id)
	//mc_bind_ips, _ := model_project.GetBindIp(id)


	//go func (){
		var cmd *exec.Cmd
		var out []byte
		var cmd_line string
		if SystemType == "windows"{
			cmd = exec.Command("ipconfig")
			out, _ = cmd.CombinedOutput()
			cmd_line  = utils.ConvertToString(string(out), "gbk", "utf-8")
		}else{
			cmd = exec.Command("/webser/dogo.sh")
			out, _ = cmd.CombinedOutput()
			cmd_line = string(out)
		}

	//}()



	this.ajaxReturn(cmd_line, "success", 200)

}

/*
执行shell命令
 */
 func (this *PublishController) RunExec(){


	 this.setTpl("run_exec.html")
 }

 /*
 执行操作
  */
  func (this *PublishController) RunExecDo(){

	  var cmd *exec.Cmd
	  var out []byte
	  var cmd_line string

	  cmd = exec.Command("dir")



	  out, _ = cmd.CombinedOutput()
	  cmd_line  = utils.ConvertToString(string(out), "gbk", "utf-8")



	  this.ajaxReturn(cmd_line, "success", 200)
  }






